using System.Data.Linq;
using System.Linq;

using vurfu.DataContracts.Graphs;
using vurfu.Linq;
using vurfu.Objects;
using vurfu.Repositories.Interfaces;

using Group = vurfu.DataContracts.Group;

namespace vurfu.Repositories
{
    public class EventGroupRepository : IEventGroupRepository
    {
        public EventGroupEdge GetEdge(string eventId, string groupId)
        {
            EventGroupEdge eventGroupEdge;
            using (DataContext connection = DataContextFactory.Create())
            {
                IQueryable<EventGroupEdge> eventGroupEdges = from edge in connection.GetTable<EventGroupEdge>()
                                                                       where edge.GroupId == groupId
                                                                       where edge.EventId == eventId
                                                                       select edge;
                eventGroupEdge = eventGroupEdges.First();
            }
            return eventGroupEdge;
        }

        public Event[] GetEvents(string groupId)
        {
            return new Event[] {};
        }

        public Group[] GetGroups(string eventId)
        {
            return new Group[] {};
        }

        public void SaveEdge(EventGroupEdge edge)
        {
            using (DataContext connection = DataContextFactory.Create())
            {
                connection.GetTable<EventGroupEdge>().InsertOnSubmit(edge);
                connection.SubmitChanges();
            }
        }
    }
}